<template>
  <div id="supplier">
    <div class="list-container">
      <div class="tables">
        <el-table
          :data="tableData"
          class="table"
          height="100%"
          ref="jdjgTable"
          @sort-change="sortChange"
          :header-cell-style="{
            padding: '0px',
            background: 'linear-gradient(0deg, #F4F6F9, #EAECF4, #F3F6F9)'
          }"
          :row-class-name="tabRowClassName"
          header-row-class-name="mapTable_th"
        >
          <el-table-column width="60" align="center" type="index" :index="addIndex" label="序号">
            <el-table-column width="60" align="center" type="index" label="检索"> </el-table-column>
          </el-table-column>
          <el-table-column label="企业名称" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="enterpriseName">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="企业类型" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="enterpriseProfitType">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.enterpriseProfitType | enterpriseProfitTypeFilter }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="企业性质" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="enterpriseNature">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.enterpriseNature | enterpriseNatureFilter }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="主要物资类别" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="materialType">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="用户名" align="center" width="180">
            <el-table-column width="180" align="center" sortable="custom" prop="userName">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="手机号" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="phone">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="状态" align="center" width="100">
            <el-table-column align="center" prop="reviewState" width="100">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.reviewState | reviewStateFilter }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="80">
            <el-table-column align="center" width="80">
              <template slot-scope="scope">
                <div class="" v-if="scope.row.reviewState == 0">
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    审核
                  </el-button>
                </div>
                <div class="" v-else>
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    查看
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="pags">
      <element-pagination @getData="getPagChange" :Total="total"> </element-pagination>
    </div>
    <el-dialog
      class="supplier-dialog"
      width="1200px"
      v-if="supplierVisiable"
      :center="true"
      :close-on-click-modal="false"
      title="申请入驻记录"
      :before-close="closeDialog"
      :visible.sync="supplierVisiable"
    >
      <div class="dialog-wrap">
        <p style="margin-bottom: 20px">
          <span style="margin-right: 30px; color: #666">
            用户名:
            <span style="color: #333"> {{ userName }}</span>
          </span>
          <span style="color: #666">
            手机号:
            <span style="color: #333">{{ userPhone }}</span>
          </span>
        </p>
        <div>
          <div class="tabs">
            <div>
              <el-tabs v-model.trim="curType" @tab-click="partTypeChange" type="card">
                <el-tab-pane
                  :label="item.createTime + '  提交'"
                  :name="item.id + ''"
                  v-for="item in partTypeList"
                  :key="item.id"
                >
                  <div class="form-con">
                    <div class="left">
                      <el-form ref="form" class="infoForm" label-width="130px">
                        <el-form-item label="企业名称:">
                          {{ item.enterpriseName }}
                        </el-form-item>
                        <el-form-item label="社会统一信用代码:">
                          {{ item.companyCode }}
                        </el-form-item>
                        <el-form-item label="注册工商地:">
                          {{ item.provinceName }} {{ item.cityName }} {{ item.areaName }}
                        </el-form-item>
                        <el-form-item label="单位法人:">
                          {{ item.legalPerson }}
                        </el-form-item>
                        <el-form-item label="业务联系人:">
                          {{ item.contacts }}
                        </el-form-item>
                        <el-form-item label="联系人手机号:">
                          {{ item.phone }}
                        </el-form-item>
                        <el-form-item label="企业类型:">
                          {{ item.enterpriseProfitType | enterpriseProfitTypeFilter }}
                        </el-form-item>
                        <el-form-item label="企业性质:">
                          {{ item.enterpriseNature | enterpriseNatureFilter }}
                        </el-form-item>
                        <el-form-item label="营业期限:">
                          {{ item.businessStart }} 至 {{ item.businessEnd || '长期' }}
                        </el-form-item>
                        <el-form-item label="纳税人资格:">
                          {{ item.taxpayerQualification | taxpayerQualificationFilter }}
                        </el-form-item>
                        <el-form-item label="主营物资类别:">
                          {{ item.materialType }}
                        </el-form-item>
                        <el-form-item label="营业执照扫描件:">
                          <el-image
                            style="width: 150px; height: 150px; margin-top: 13px"
                            :src="item.businessLicense"
                            alt=""
                            v-if="item.businessLicense"
                          ></el-image>
                          <span v-else>--</span>
                        </el-form-item>
                        <el-form-item label="注册邀请码:">
                          {{ item.invitationCode || '--' }}
                        </el-form-item>
                      </el-form>
                    </div>
                    <div class="right">
                      <el-form ref="form" class="infoForm" style="margin-bottom: 20px">
                        <el-form-item label="审核状态：">
                          <span style="float: left">
                            {{ item.reviewState | reviewStateFilter }}
                          </span>

                          <el-image
                            style="width: 60px; height: 45px; margin-left: 20px"
                            :src="require('../../../../assets/unreviewed.png')"
                            v-if="item.reviewState === 0"
                          >
                          </el-image>
                          <el-image
                            style="width: 60px; height: 45px; margin-left: 20px"
                            :src="require('../../../../assets/examination_passed.png')"
                            v-else-if="item.reviewState === 1"
                          >
                          </el-image>
                          <el-image
                            style="width: 60px; height: 45px; margin-left: 20px"
                            :src="require('../../../../assets/review_rejected.png')"
                            v-else
                          >
                          </el-image>
                        </el-form-item>
                      </el-form>
                      <div v-if="item.reviewState === 0">
                        <div style="font-size: 14px; margin-bottom: 30px">
                          <p>
                            选择<span style="color: #ff0000">驳回</span>，需填写驳回理由，等待填报人修改后再次审核。
                          </p>
                          <p>选择<span style="color: #00a2ff">通过</span>，填报的工作内容将生效，不可撤销。</p>
                        </div>
                        <p style="margin-bottom: 30px">
                          <el-radio v-model.trim="radio" label="1">通过</el-radio>
                          <el-radio v-model.trim="radio" label="2">驳回</el-radio>
                        </p>
                        <div style="margin-bottom: 100px">
                          <el-form ref="form" class="infoForm">
                            <el-form-item label="审核意见：">
                              <el-input
                                type="textarea"
                                :autosize="{ minRows: 3 }"
                                placeholder="请输入审核意见"
                                v-model.trim="auditopinion"
                              >
                              </el-input>
                            </el-form-item>
                          </el-form>
                        </div>
                        <el-button type="primary" size="small" @click="subMitBtn(item.id)"> 提交审核 </el-button>
                      </div>
                      <div v-else class="isreview">
                        <el-form ref="form" class="infoForm" style="margin-bottom: 20px">
                          <el-form-item label="审核人:">
                            {{ item.reviewer }}
                          </el-form-item>
                          <el-form-item label="审核时间:">
                            {{ item.auditTime }}
                          </el-form-item>
                          <el-form-item label="审核结果:">
                            {{ item.reviewState | reviewStateFilter }}
                          </el-form-item>
                          <el-form-item label="审核意见:">
                            {{ item.remark || '--' }}
                          </el-form-item>
                        </el-form>
                      </div>
                    </div>
                  </div>
                </el-tab-pane>
              </el-tabs>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ElementPagination from '../../../../components/ElementPagination.vue'
export default {
  name: 'supplier',
  data() {
    return {
      auditopinion: '',
      curType: '',
      supplierVisiable: false,
      searchPositionName: '',
      userName: '',
      userPhone: null,
      enterpriseId: null,
      tableData: [],
      total: 0,
      page: 1,
      size: 15,
      radio: '',
      partTypeList: []
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    subMitBtn(id) {
      // console.log(id, this.radio);
      if (this.radio) {
        let flag = true
        if (this.radio === '2' && !this.auditopinion) {
          this.$message.error('请填写驳回理由')
          flag = false
        }
        if (flag) {
          this.$https({
            url: '/government/supplierSettledReview',
            method: 'post',
            data: {
              remark: this.auditopinion,
              id: id,
              agree: this.radio == 1 ? true : false
            }
          }).then(res => {
            if (res.code === 0) {
              this.$message.success('审核成功')
              this.getTabs()
              this.getData()
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      } else {
        this.$message.error('请选择审核结果')
      }
    },
    partTypeChange(e) {},
    handleClick(scope) {
      this.userName = scope.userName
      this.userPhone = scope.phone
      this.enterpriseId = scope.enterpriseId
      this.supplierVisiable = true
      this.getTabs()
    },
    closeDialog(done) {
      this.userName = ''
      this.userPhone = ''
      this.partTypeList = []
      done()
    },
    getDataChange() {},
    getPagChange(data) {
      this.page = data.currentPage
      this.size = data.pagesize
      this.getData()
    },
    // 获取历史所有审核记录选项卡
    getTabs() {
      this.$https({
        method: 'post',
        url: '/government/supplierCertificateRecord',
        data: {
          enterpriseId: this.enterpriseId,
          page: 1,
          size: 9999
        }
      })
        .then(res => {
          if (res.code === 0) {
            this.partTypeList = res.data.records
            this.curType = this.partTypeList[0]['id'] + ''
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    getData() {
      this.$https({
        method: 'post',
        url: '/government/supplierSettledReviewList',
        data: {
          page: this.page,
          reviewState: null,
          size: this.size
        }
      })
        .then(res => {
          if (res.code === 0) {
            this.total = res.data.total
            this.tableData = res.data.records
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.page - 1) * this.size
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  },
  components: {
    ElementPagination
  },
  filters: {
    enterpriseProfitTypeFilter(val) {
      let type = ''
      switch (val) {
        case 0:
          return (type = '国营')
        case 1:
          return (type = '民营')
        case 2:
          return (type = '外资')
        case 3:
          return (type = '合资')
        case 4:
          return (type = '个性工商户')
        default:
          break
      }
      return type
    },
    enterpriseNatureFilter(val) {
      if (val === null) {
        return
      }
      return val === 0 ? '贸易商' : val === 1 ? '代理商' : '生成商'
    },
    taxpayerQualificationFilter(val) {
      if (val === null) {
        return
      }
      return val === 0 ? '增值税一般纳税人' : val === 1 ? '增值税小规模纳税人' : '非增值税纳税人'
    },
    reviewStateFilter(val) {
      if (val === null) {
        return
      }
      return val === 0 ? '未审核' : val === 1 ? '审核通过' : '审核驳回'
    }
  }
}
</script>
<style lang="less" scoped>
.supplier-dialog {
  .dialog-wrap {
    width: 100%;
  }
  .form-con {
    border: 1px solid #d6d6d6;
    border-top: none;
    display: flex;
    padding: 20px 0;
    .left {
      width: 50%;
      border-right: 1px dashed #d6d6d6;
      padding: 0 50px;
    }
    .right {
      width: 50%;
      padding: 0 50px;
    }
  }
}
</style>
<style lang="less">
#supplier {
  height: 100%;
  .list-container {
    height: calc(100% - 62px);
    .tables {
      height: 100%;
    }
  }
  .supplier-dialog {
    .el-tabs__nav-next,
    .el-tabs__nav-prev {
      position: absolute;
      cursor: pointer;
      line-height: 34px;
      font-size: 18px;
      border: 1px solid #d6d6d6;
      border-bottom: none;
      color: #909399;
    }
    .left {
      .el-form-item__label {
        color: #666;
      }
      .el-form-item__content {
        color: #333;
      }
    }
    .right {
      .el-form-item__label,
      .el-form-item__content {
        color: #333;
        font-size: 16px;
      }
      .el-form-item__content {
        font-weight: 600;
      }
    }
    .el-form-item {
      margin-bottom: 0;
    }
    .el-tabs__item {
      height: 32px;
      line-height: 30px;
    }
    .el-button {
      width: 280px;
      color: #fff;
      background-color: #fa7355;
      border: none;
      border-radius: 5px;
    }
    .el-tabs__header {
      margin: 0;
    }
    .el-tabs__header .el-tabs__nav {
      border-radius: 0px;
    }
  }
}
</style>
